﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using nRoute.Components;
using nRoute.Components.Composition;
using nRoute.Components.Messaging;
using nRoute.Navigation.Mapping;
using nRoute.ViewModels;
using nRouteWizard.Wizard.Views;

namespace nRouteWizard.Wizard.ViewModels
{
	[DefineNavigationContent("Content/Wizards/WidgetConfiguration/Step3/", typeof(WidgetConfigurationStep3View))]
	[MapViewModel(typeof(WidgetConfigurationStep3View))]
	public class WidgetConfigurationStep3ViewModel : NavigationViewModelBase
	{
		private const string SETTINGS_KEY = "Setting";

		private string _setting;

		public WidgetConfigurationStep3ViewModel()
		{
		}

#region Properties

		public string Setting
		{
			get { return _setting; }
			set
			{
				if (!string.Equals(_setting, value, StringComparison.Ordinal))
				{
					_setting = value;
					NotifyPropertyChanged(() => Setting);
					Channel<SettingInfo>.Publish(new SettingInfo() { SettingIndex = 3, Setting = this.Setting });
				}
			}
		}

#endregion

#region State Management

		protected override void OnRestoreState(ParametersCollection state)
		{
			if (state != null && state.ContainsKey(SETTINGS_KEY))
			{
				this.Setting = Convert.ToString(state[SETTINGS_KEY]);
			}			
		}

		protected override ParametersCollection OnSaveState()
		{
			return new ParametersCollection()
			{
				new Parameter() { Key = SETTINGS_KEY, Value = this.Setting }
			};
		}


#endregion

	}
}
